package com.shen.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.shen.server.pojo.Employee;
import com.shen.server.pojo.ResPageBean;
import com.shen.server.pojo.RespBean;
import com.shen.server.pojo.Salary;
import com.shen.server.service.IEmployeeService;
import com.shen.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {

    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;

    @ApiOperation(value = "获取所有工资账套")
    @GetMapping("/salarys")
    public List<Salary> getAllSalarySobCfg(){
        return salaryService.list();
    }

    @ApiOperation(value = "获取所以员工账套(分页)")
    @GetMapping("/")
    public ResPageBean getEmplWithSlary(@RequestParam(defaultValue = "1") Integer currenPage,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        Employee employee){

        return employeeService.getEmplWithSlary(currenPage,size,employee);
    }

    @ApiOperation(value = "更新员工账套")
    @PutMapping("/")
    public RespBean updateEmplWithSalary(Integer eid, Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid))){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }   
}
